<template>
  <div class="app-container1 show-back-class">
    <div style="width: 100%;height: 60px;border-bottom: #1C97FF 1px solid;padding:  10px 20px;display: flex;">
      <img style="width: 340px; height: 40px; margin-right: 20px;" src="@/assets/bigScreen/index/LOGO.jpg" alt="">
      <big-tab-Bar />
    </div>
    <div class="content-bottom">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="分类" prop="categorizeCode">
        <el-cascader  v-model="categorizeCodeArr" style="width: 500px" @change="changeCategorizeCode"
                      :options="$store.state.factorDict.categorizeTreeDict"
          :props="{value:'id',label:'chineseName',children:'children',checkStrictly:true,}"
          clearable></el-cascader>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option class="index-option" v-for="dict in $store.state.factorDict.statusOptions"
                     :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['factor:carbonFactorInfo:save']" >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['factor:carbonFactorInfo:remove']" >删除</el-button>
      </el-col>
	  <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table v-loading="loading" :data="carbonFactorInfoList" @selection-change="handleSelectionChange" border :height="tableHeight">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" width="50" />
<!--      <el-table-column label="编号" align="center" prop="id" width="50" />-->
      <el-table-column label="分类" align="center" prop="categorizeCode" width="500">
        <template slot-scope="scope">
         <span v-if="scope.row.categorizeCode">
           {{selectDictLabels($store.state.factorDict.categorizeInfoOptions, scope.row.categorizeCode,',','id','chineseName')}}
         </span>
        </template>
      </el-table-column>
      <el-table-column label="上游排放" align="center" prop="upstreamEmissions" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ scope.row.upstreamEmissions}}【{{ scope.row.upstreamUnit}}】
        </template>
      </el-table-column>
      <el-table-column label="下游排放" align="center" prop="downstreamEmissions"  :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ scope.row.downstreamEmissions}}【{{ scope.row.downstreamUnit}}】
        </template>
      </el-table-column>
<!--      <el-table-column label="参考文献/数据来源" align="center" prop="dataSource" />-->
      <el-table-column label="参考文献/简化" align="center" prop="dataSourceSimplified" />
      <el-table-column label="负责人" align="center" prop="principal" width="150" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="排序" align="center" prop="orderNum" width="100"/>-->
      <el-table-column label="状态" align="center" prop="status" width="80">
        <template slot-scope="scope">
          {{selectDictLabelDefault($store.state.factorDict.statusOptions, scope.row.status)}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="80">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['factor:carbonFactorInfo:save']" >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <change-form ref="changeFormRef" @getList="getList" />
    </div>
  </div>
</template>

<script>
import { listCarbonFactorInfo, getCarbonFactorInfo, delCarbonFactorInfo, addCarbonFactorInfo, updateCarbonFactorInfo, exportCarbonFactorInfo } from "@/api/factor/carbonFactorInfo";
import ChangeForm from "./changeForm"
import bigTabBar from '@/views/components/bigTabBar/index'
export default {
  name: "CarbonFactorInfo",
  components:{
    ChangeForm,bigTabBar
  },
  data() {
    return {
      categorizeCodeArr: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 碳排放因子数据库表格数据
      carbonFactorInfoList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        categorizeCode: null,
        upstreamEmissions: null,
        upstreamUnit: null,
        downstreamEmissions: null,
        downstreamUnit: null,
        dataSource: null,
        dataSourceSimplified: null,
        principal: null,
        status: null,
        orderNum: null,
      },
      tableHeight: '',
    };
  },
  created() {
    this.tableHeight = window.innerHeight - 240;
    this.getList();
  },
  methods: {
    changeCategorizeCode(list){
      this.queryParams.categorizeCode = list.join(",");
      if(list.length<3){
        this.queryParams.categorizeCode =this.queryParams.categorizeCode+",";
      }
    },
    /** 查询碳排放因子数据库列表 */
    getList() {
      this.loading = true;
      listCarbonFactorInfo(this.queryParams).then(response => {
        this.carbonFactorInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length!==1;
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.changeFormRef.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.changeFormRef.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCarbonFactorInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },

  }
};
</script>
<style lang="scss" scoped>
.app-container1{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000D17;
  // background: url("../../assets/bg2.jpg") no-repeat;
  // background-size: 100% 100%;
}
.content-bottom{
  width: 100%;
  height: calc(100% - 60px);
  background-color: #000D17;
  padding: 20px;
}
</style>